﻿Imports VN.INS.BL.BC
Imports System.Data
Imports System.Web

Partial Class Devida_Prueba
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not (Page.IsPostBack)) Then

            Dim sJScript As String = "<script type=""text/javascript"" src=""https://apis.google.com/js/plusone.js""> {lang: 'es-419'} </script>" & _
             "<div id=""container""><div id=""header"">" & _
             "<table width=""100%""><tr> <td width=""35%""><h1 style=""font-size:50px"">El sensey</h1></td><td align=""right""><div style=""float:right""><div id=""tuto""><strong> Tutoriales</strong><br> <a href=""http://www.javaya.com.ar"" target=""_blank"">Java Ya</a><br><a href=""http://www.javaya.com.ar/androidya"" target=""_blank"">Android Ya</a><br>  <a href=""http://www.csharpya.com.ar"" target=""_blank"">C# Ya</a></div><br><span style=""text-align:right""><g:plusone></g:plusone></span><br><a style=""font-size:9px;margin-right:11px"" href=""politicas.htm"">Políticas de privacidad.</a></div></td></tr></table></div>"
            Response.Write(sJScript)


            Session("Año") = "2012"
            Session("Nombre") = ""
            Session("DESCRIPCION") = ""
            Session("ABREVIATURA") = ""
            Session("perfil") = ""
            Dim strPar As String = Request.QueryString("POA")
            strPar = "POA-0288"
            Me.GridView1.EditIndex = -1
            Me.GridView1.DataSource = LISTA_COMPONENTE(strPar)
            Me.GridView1.DataBind()
        End If
    End Sub

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim datos As DataTable
        datos = New DataTable
        datos = ViewState("datoPrueba")
        'Crear código
        Dim strCodigo As String
        strCodigo = lblID.Text

        Dim rowfs As DataRow = datos.Rows(hdIndice.Value) 'NewRow()
        rowfs("COMPONENTE") = txtfname.Text
        rowfs("DESCRIPCION") = txtlname.Text
       
        'datos.Rows.Add(rowfs)
        Me.GridView1.DataSource = datos
        Me.GridView1.DataBind()
    End Sub

    Protected Sub imgbtn_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        Dim btndetails As ImageButton = TryCast(sender, ImageButton)
        Dim gvrow As GridViewRow = DirectCast(btndetails.NamingContainer, GridViewRow)
        lblID.Text = GridView1.DataKeys(gvrow.RowIndex).Value.ToString()
        hdIndice.Value = gvrow.RowIndex
        Dim dv As DataView = New DataView(ViewState("datoPrueba"), "COMPONENTE='" + lblID.Text + "'", "COMPONENTE", DataViewRowState.CurrentRows)
        Dim dt As DataTable
        dt = New DataTable
        dt = dv.ToTable()
        txtlname.Text = dt.Rows(0).Item("descripcion").ToString
        txtfname.Text = dt.Rows(0).Item("componente").ToString
        Hola.Mostrar(txtlname.Text)
        'Me.ModalPopupExtender1.Show()
    End Sub

    Public Function LISTA_COMPONENTE(ByVal poac As String) As DataTable
        Dim ObjMantenimientoPoaBC As MantenimientoPoaBC
        Dim ObjData As DataTable
        ObjMantenimientoPoaBC = New MantenimientoPoaBC
        ObjData = New DataTable
        ObjData = ObjMantenimientoPoaBC.LISTA_COMPONENTE(poac)
        ViewState("datoPrueba") = ObjData
        Return ObjData
    End Function

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        Me.GridView1.EditIndex = e.NewEditIndex
        Me.GridView1.DataSource = LISTA_COMPONENTE("POA-0015")
        Me.GridView1.DataBind()

        Dim txtId As TextBox = CType(GridView1.Rows(e.NewEditIndex).FindControl("txtId"), TextBox)
        Dim ddlNombre As DropDownList = CType(GridView1.Rows(e.NewEditIndex).FindControl("ddlNombre"), DropDownList)        
        Dim dttip As DataTable
        dttip = LISTA_COMPONENTE("POA-0015")
        Dim drttiprow As DataRow = dttip.NewRow()
        drttiprow("id") = "--Seleccione--"
        drttiprow("nombre") = ""
        dttip.Rows.Add(drttiprow)
        ddlNombre.DataSource = dttip
        ddlNombre.DataTextField = "nombre"
        ddlNombre.DataValueField = "id"
        ddlNombre.DataBind()
        ddlNombre.SelectedValue = txtId.Text
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        Me.GridView1.EditIndex = -1
        Me.GridView1.DataSource = LISTA_COMPONENTE("POA-0015")
        Me.GridView1.DataBind()
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim txtId As TextBox = CType(GridView1.Rows(e.RowIndex).FindControl("txtId"), TextBox)
        Dim ddlNombre As DropDownList = CType(GridView1.Rows(e.RowIndex).FindControl("ddlNombre"), DropDownList)

        Dim xtrId As String = GridView1.DataKeys(e.RowIndex).Values(0).ToString
        Dim xtrNombre As String = GridView1.DataKeys(e.RowIndex).Values(1).ToString

        'Actualizar en session
        MsgBox(ddlNombre.SelectedItem.Text)

        Me.GridView1.EditIndex = -1
        Me.GridView1.DataSource = LISTA_COMPONENTE("POA-0015")
        Me.GridView1.DataBind()
    End Sub

End Class
